package edu.zsl.controller;

import edu.zsl.service.AccountService;
import jakarta.servlet.http.Cookie;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
public class LoginController {
    private final AccountService accountService;
    @Autowired
    public LoginController(AccountService accountService) {
        this.accountService = accountService;
    }
    @GetMapping({"/", "/login"})
    public String loginPage(Model model){
        model.addAttribute("title","教务系统");
        return "login";
    }
    @PostMapping("/login")
    public String login(String username, String password, Model model){
        boolean result = accountService.validate(username, password);
        if (result){
            return "index";
        }
        return "login";
    }
}
